/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.cqq.impl;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.yunhoo.cqq.model.CodeBase;
import com.yunhoo.cqq.model.LawTypeData;
import com.yunhoo.cqq.model.Statute;
import com.yunhoo.sys.db.util.IbatisTemplate;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class IbatisStatute {

    private final static String NAMESPACE  = "Statute.";
    private static SqlMapClient sqlmapclient = IbatisTemplate.getSqlMapClient();

    public static void insertStatute(Statute statute) {//插入cf_announcement上传的文档
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.insert(NAMESPACE+"insertStatute", statute);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误insertStatutement~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static List getAllStatute() {  //获得cf_announcement所有法规
        List<Statute> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"getAllStatute",new Statute());
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getAllStatute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static List getTop3Statute() {  //获得最新3条法规
        List<Statute> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"getTop3Statute",new Statute());
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getTop3Statute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static List getTop5Statute() {  //获得最新3条法规
        List<Statute> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"getTop5Statute",new Statute());
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getTop5Statute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static List getLeavingStatute() {  //获得最新3条法规
        List<Statute> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"getLeavingStatute",new Statute());
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getLeavingStatute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static Object getTop1Statute() {  //获得最新法规
        Statute statute = new Statute();
        try {
            sqlmapclient.startTransaction();
            statute = (Statute) sqlmapclient.queryForObject(NAMESPACE+"getTop1Statute",new Statute());
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getTop1Statute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return statute;
    }

    public static Object getStatuteById(String id) {  //根据id获得法规
        Statute statute = new Statute();
        try {
            sqlmapclient.startTransaction();
            
            Statute param = new Statute();
            param.setId(id);
            statute = (Statute) sqlmapclient.queryForObject(NAMESPACE+"getStatuteById", param);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getStatuteById~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return statute;
    }

    public static List getSelectStatute(String id) {  //获得cf_announcement某类型的法规
        List<Statute> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            
            Statute param = new Statute();
            param.setId(id);
            list = sqlmapclient.queryForList(NAMESPACE+"getSelectStatute", param);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getSelectStatute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static void deleteSelectStatute(Statute statute) {//删除选中法规
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.delete(NAMESPACE+"deleteSelectStatute", statute);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误deleteSelectStatute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void updateSelectStatuteAudit(Statute statute) {//更新法规审核状态
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.update(NAMESPACE+"updateSelectStatuteAudit", statute);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误updateSelectStatuteAudit~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void cancelSelectStatuteAudit(Statute statute) {//取消法规审核
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.update(NAMESPACE+"cancelSelectStatuteAudit", statute);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误cancelSelectStatuteAudit~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void updateStatute(Statute statute) {//更新法规
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.update(NAMESPACE+"updateStatute", statute);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误updateStatute~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static List getRootLawType() {
        List<LawTypeData> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"getRootLawType",new LawTypeData());
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getRootDocType~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static List getSubLawType(LawTypeData lawTypeData) {
        List<LawTypeData> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"getSubLawType", lawTypeData);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getSubDocType~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static List checkLawRepeat(LawTypeData type) { //获得所选文档类型节点的所有文档
        List<LawTypeData> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"checkLawRepeat", type);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误checkDocRepeat~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static List checkLawParent(LawTypeData type) { //查看是否有父节点
        List<LawTypeData> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"checkLawParent", type);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误checkDoctypeParent~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static void insertLawtype(LawTypeData base) {//插入doctype
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.update(NAMESPACE+"insertLawtype", base);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误insertDoctype~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void updateLawtype(LawTypeData base) {//更新doctype
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.update(NAMESPACE+"updateLawtype", base);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误updateDoctype~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void updateLawIsEnd(CodeBase base) {//更新doctype isEnd属性
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.update(NAMESPACE+"updateLawtypeIsEnd", base);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误updateDoctypeIsEnd~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static List getLawSameLevel(CodeBase base) { //查看是否有同级节点
        List<LawTypeData> list = new ArrayList();
        try {
            sqlmapclient.startTransaction();
            list = sqlmapclient.queryForList(NAMESPACE+"getLawSameLevel", base);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误getDoctypeSameLevel~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static void deleteLawByid(LawTypeData announce) {//删除选中公告
        try {
            sqlmapclient.startTransaction();
            sqlmapclient.delete(NAMESPACE+"deleteLawByid", announce);
            sqlmapclient.commitTransaction();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println(NAMESPACE+"查询错误deleteSelectAnnounce~~");
        } finally {
            try {
                sqlmapclient.endTransaction();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
